package com.main.tripplanner.persistent;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="attractions")
public class Attraction extends PersistentEntity{

	public enum AttractionType{
		FAMILY (1),
		NIGHT_LIFE (2),
		TREKKING (3),
		EXTREME (4),
		CULTURE (5);

		private int id; 
		private AttractionType(int value){
			id=value;
		}

		public int getId(){
			return id;
		}
	}

	private String name;
	private float time;
	private float enjoymentLevel;
	private int enjoymentLevelVotes;
	private AttractionType attractionType;
	private City city;
	//to keep relative potential
	@JsonIgnore
	private int potential;


	@Id
	@Column(name="attraction_id")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}

	@Column(name="name")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	@Column(name="time_to_spend")
	public float getTime() {
		return time;
	}
	public void setTime(float time) {
		this.time = time;
	}

	@Column(name="enjoyment_level")
	public float getEnjoymentLevel() {
		return enjoymentLevel;
	}
	public void setEnjoymentLevel(float enjoymentLevel) {
		this.enjoymentLevel = enjoymentLevel;
	}

	@Column(name="enjoyment_level_votes")
	public int getEnjoymentLevelVotes() {
		return enjoymentLevelVotes;
	}

	public void setEnjoymentLevelVotes(int enjoymentLevelVotes) {
		this.enjoymentLevelVotes = enjoymentLevelVotes;
	}

	@Enumerated(EnumType.ORDINAL)
	@Column(name="attraction_type_id")
	public AttractionType getAttractionType() {
		return attractionType;
	}
	public void setAttractionType(AttractionType attractionType) {
		this.attractionType = attractionType;
	}


	@ManyToOne
	@JoinColumn(name="city_id")
	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	@Transient
	public int getPotential() {
		return potential;
	}
	public void setPotential(int potential) {
		this.potential = potential;
	}

	@Override
	public boolean equals(Object o) {
		if(o == null)
			return false;

		if(!(o instanceof Attraction))
			return false;
		Attraction otherAttraction = (Attraction) o;
		if(!(otherAttraction.getId() ==this.getId()))
			return false;
		return true;
	}
	
	public int hashcode() {
	    int hash = 3;
	    hash = 47 * hash + ((this.getName() != null) ? this.getName().hashCode() : 0);
	    return hash;
	}
}

